package com.sky.mapper;


import com.github.pagehelper.Page;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.enumeration.OperationType;
import com.sky.operation.Note;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 新增菜品
     * @param dish
     */
    @Note(value = OperationType.INSERT)
    void dishesInsert(Dish dish);

    @Note(value = OperationType.UPDATE)
    void dishUpdate(Dish dish);

    void tasteUpdate(DishFlavor dishFlavor);

    /**
     * 分页查询
     * 根据id查询
     * @param id
     * @return
     */
    DishVO queryById(Long id);

    /**
     * 方法1 不推荐
     * 菜品删除
     * @param ids
     */
    @Delete("delete from dish where id = #{id}")
    void dishDelete(Long ids);

    /**
     * 分页查询
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> queryList(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 根据主键查询菜品
     * @param id
     * @return
     */
    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    /**
     * 方法2
     * 菜品删除
     * @param ids
     */
    void dishDeleteList(List<Long> ids);

    @Select("select * from dish where category_id = #{id}")
    List<Dish> listById(Long id);

    List<Integer> idList(List<Long> dishIdList);

    List<DishVO> getByDishId(Dish dish);


    // DishVO queryAllByIdDishVo(Long id);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
